<?php
/**
 * Created by PhpStorm.
 * User: 聪
 * Date: 2019/4/18
 * Time: 1:29
 */

namespace app\http\middleware;

use traits\controller\Jump;

class Auth
{
    use Jump;

    public function handle($request, \Closure $next)
    {
        $token = $request->header('authorization');
        if ($token) {
            $userInfo = decrypt(ltrim($token, 'Bearer '), 'user_info');
            if (time() >= $userInfo['end_time']) $userInfo['save_status'] = false;
            $key = $request->module() == 'front' ? 'front_user' : 'backstage_user';
            $request->$key = $userInfo;
        }
//        else{
//            $this->result([],500,'您尚未登录',401);
//        }
        return $next($request);
    }
}